<h1>Listing orders</h1>

<table>
<% for order in [nil] + @orders %>
  <tr>
  <% for column in Order.content_columns %>
   <% if !['comments', 'created_by'].include?(column.name) %>  
     <% if order.nil? %>
      <th><%= column.human_name %></th>   
     <% else %>
      <% val = order.send(column.name)  %>
      <td><%= case column.name 
                when 'state' then format_state val
                when 'orderer' then auto_link(h(val))
                else h val
              end %></td>
     <% end %>
   <% end %>
  <% end %>
  <% if order.nil? %>
    <th>Supplier</th>
    <th colspan='3'>Action</th>
  <% else %>
       <td><%=h order.supplier.name unless order.supplier.nil? %></td>
    <td><%= link_to 'Show', :action => 'show', :id => order %></td>
    <td><%= link_to 'Edit', :action => 'edit', :id => order %></td>
    <td><%= link_to 'Destroy', { :action => 'destroy', :id => order }, :confirm => 'Are you sure?', :method => :post if order.state == Order::STATE_NEW %></td>
  <% end %>  
  </tr>
<% end %>
</table>

<%= link_to 'New order', :action => 'new' %> 

<div class='prevnext_links'>
  <%= link_to 'Previous page', { :page => @order_pages.current.previous } if @order_pages.current.previous %>
  <%= link_to 'Next page', { :page => @order_pages.current.next } if @order_pages.current.next %> 
</div>
